package cn.dakaqi.utils.qq;

import com.qq.connect.QQConnectException;
import com.qq.connect.api.OpenID;
import com.qq.connect.api.weibo.UserInfo;
import com.qq.connect.javabeans.weibo.UserInfoBean;

/**
 * Created by chunyang on 2016/4/20.
 */
public class QQUtils
{
    /**
     * 根据TOKEN 获取openid
     * @param token
     * @return
     */
    public static String getOPenId(String token)
    {
        try
        {
            OpenID openIDObj = new OpenID(token);
            String openid = openIDObj.getUserOpenID();
            return openid;
        } catch (QQConnectException e)
        {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取微薄名称
     * @param token
     * @param openid
     * @return
     */
    public static String getWeiBoName(String token,String openid)
    {
        String wbName = "";
        try
        {
            UserInfo weiboUserInfo = new UserInfo(token, openid);
            UserInfoBean wu = weiboUserInfo.getUserInfo();

            if (wu.getRet() == 0)
            {
                wbName = wu.getName();
            }
        } catch (QQConnectException e)
        {
            e.printStackTrace();
        }

        return wbName;
    }
}
